<template>
  <div class="news">
    <img class="news-headerImg" src="@/assets/img/headerImg.png" alt="">
    <div class="news-main">
      <div class="news-left">
        <el-menu
          default-active="1"
          class="el-menu-vertical-demo"
          @select="handleSelect"
          background-color="#ffffff"
          text-color="#555555"
          active-text-color="#ffffff">
          <el-menu-item index="1">
            <span slot="title">最新资讯</span>
          </el-menu-item>
          <el-menu-item index="2">
            <span slot="title">企业公告</span>
          </el-menu-item>
          <el-menu-item index="3">
            <span slot="title">行业新闻</span>
          </el-menu-item>
        </el-menu>
      </div>
      <div class="news-right">
        <h1>行业资讯</h1>
        <p></p>
<!--        <p class="news-crumbs">您的位置：行业资讯 > {{currentPath}}</p>-->
        <div class="news-crumbs">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/news' }">行业资讯</el-breadcrumb-item>
            <el-breadcrumb-item>{{currentPath}}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="news-right-main">
          <div class="news-right-content" v-for="(item,index) in newsList" :key="index">
            <img :src="$api.picPre + item.pic" alt="">
            <div>
              <p class="news-content-title">{{item.title}}</p>
              <p>{{item.create_time}}</p>
              <p class="news-content-details">{{item.simple}}</p>
              <p class="news-content-btn" @click="lookBtn(item.id)">查看详情</p>
            </div>
          </div>
          <el-pagination
            background
            layout="prev, pager, next"
            :page-size="10"
            @current-change="handleCurrentChange"
            :total="pagination.total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'news',
  data () {
    return {
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      },
      currentPath: '最新资讯',
      column: '',
      newsList: []
    }
  },
  methods: {
    lookBtn (id) {
      this.$router.push({
        name: 'newsDetails',
        params: { id: id }
      })
    },
    handleCurrentChange (val) {
      this.pagination.current = val
      this.getNewsList()
    },
    handleSelect (key) {
      switch (key) {
        case '1':
          this.currentPath = '最新资讯'
          this.column = ''
          break
        case '2':
          this.currentPath = '企业公告'
          this.column = 2
          break
        case '3':
          this.currentPath = '行业新闻'
          this.column = 1
          break
      }
      this.getNewsList()
    },
    getNewsList () {
      this.$ajax
        .get(this.$api.infoList, {
          page_size: this.pagination.pageSize,
          page: this.pagination.current,
          section: this.column
        })
        .then(res => {
          for (let item of res.data) {
            item.create_time = item.create_time.split(' ')[0]
          }
          this.newsList = res.data
          this.pagination.total = res.total_count
        })
        .catch(err => {
          this.$message({
            message: err,
            type: 'warning'
          })
        })
    }
  },
  created () {
    this.getNewsList()
  }
}
</script>
<style  scoped lang="scss">
.news{
  background-color: #F5F5F5;
  .news-headerImg{
    width: 100%;
    height: 240px;
  }
  .news-main{
    width: 1200px;
    margin: 0 auto;
    position: relative;
    top: -150px;
    @include flex_content;
    .news-left{
      width: 240px;
      height: 330px;
      padding-top: 190px;
      margin-right: 20px;
    }
    .news-right{
      @include flex_one;
      h1{
        color: #FFFFFF;
        font-size: 26px;
        margin-bottom: 16px;
      }
      h1+p{
        height: 2px;
        width: 100px;
        background-color: #FFFFFF;
        margin-bottom: 15px;
      }
      .news-crumbs{
        color: #CCCCCC;
        font-size: 14px;
        margin-bottom: 41px;
      }
      .news-right-main{
        width: 100%;
        background-color: #FFFFFF;
        padding: 0px 29px 32px 20px;
        .news-right-content{
          padding: 20px 0;
          border-bottom: 1px solid #E6E6E6;
          @include flex_content;
          img{
            width: 210px;
            height: 140px;
          }
          div{
            margin-left: 20px;
            .news-content-title{
              font-size: 16px;
              color: #92282A;
              margin-bottom: 13px;
            }
            .news-content-title+p{
              font-size: 12px;
              color: #969696;
              margin-bottom: 13px;
            }
            .news-content-details{
              height: 42px;
              font-size: 14px;
              color: #555555;
              line-height: 21px;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
            .news-content-btn{
              width: 100px;
              height: 30px;
              text-align: center;
              line-height: 30px;
              background-color: #FFFFFF;
              border: 1px solid #E6E6E6;
              color: #555555;
              font-size: 14px;
              margin-top: 14px;
              box-sizing: border-box;
            }
            .news-content-btn:hover{
              background-color: #92282A;
              border: 1px solid #92282A;
              color: #FFFFFF;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
}
</style>
